### 4.2

cervejas <-c("chope","lata","garrafa","chope","garrafa", "garrafa","lata","lata","nenhuma","lata","garrafa","garrafa", "garrafa","lata","lata","lata","garrafa","lata","chope","nenhuma", "garrafa","garrafa","garrafa","chope","garrafa","garrafa","chope","garrafa","lata","lata")
cervejas.t <- table(cervejas)

dotchart(cervejas.t)
barplot(cervejas.t)

#2. dotplot tem maior razo dado/tinta


#? barplot(as.matrix(table(cervejas)))
#? dotchart(as.matrix(table(cervejas)))



### 4.3

caixeta  <- read.csv("caixeta.csv",as.is=T)

head(caixeta)
dap = caixeta$cap/pi
hist(dap)

c1 <- aggregate(caixeta$h, list(caixeta$arvore,caixeta$local), FUN=max)
str(c1)

library(lattice)
histogram(Group.1~x|Group.2,data=c1)

#3.  possvel ver uma maior concentrao de rvores mais altas na direo retiro>chauas>jureia



### 4.4

egrandis <- read.csv("egrandis.csv", as.is=T, sep=";")
boxplot(dap~rotacao, egrandis)
boxplot(dap~regiao, egrandis)
qqnorm(egrandis$ht)
qqline(egrandis$ht,col="red",lwd=2)



### 4.5

caixeta <- read.csv("caixeta.csv", as.is=T)

tabebuia <- subset(caixeta,caixeta$especie=="Tabebuia cassinoides")
str(tabebuia)
tabebuia$dap <- tabebuia$cap/pi
t1 <- aggregate(tabebuia$dap, list(tabebuia$arvore,tabebuia$local), FUN=sum)
t2 <- aggregate(tabebuia$h, list(tabebuia$arvore,tabebuia$local), FUN=max)
colnames(t1) <- c("arvore","local","dap")
colnames(t2) <- c("arvore","local","h")
head(t1)
head(t2)

######
## possvel outlier
## identify(t2$h,t1$dap)
## t1 <- t1[-148,]
## t2 <- t2[-148,]
######

plot(t2$h,t1$dap)

scatter.smooth(t2$h,t1$dap, xlab="Altura", ylab="DAP")

library(lattice)

t1$h <- t2$h
xyplot(dap~h|local,data=t1)